package com.keffect.effects.staticEffects;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Point;
import java.awt.Rectangle;

import com.keffect.effects.StaticEffect;

/**
 * 
 * @author Matias Varela
 *         <p>
 *         Student of Licenciatura en Ciencias de la Computacion, at the
 *         Universidad Nacional del Sur (Argentina).
 *         <p>
 *         project site: http://code.google.com/p/keffect-project/
 * 
 */
public class ShadowFrame extends StaticEffect {

	// r1:left; r2:right; r3:top; r4:bottom
	protected Rectangle r1, r2, r3, r4;
	protected GradientPaint p1, p2, p3, p4;
	protected Paint defaultPaint;
	protected int px;
	protected boolean right, left, top, bottom;
	protected Color color;


	public ShadowFrame(int px) {
		super();
		this.px = px;
		this.right = true;
		this.left = true;
		this.top = true;
		this.bottom = true;
		this.color = Color.black;
	}


	public ShadowFrame(int px, Color color) {
		super();
		this.px = px;
		this.right = true;
		this.left = true;
		this.top = true;
		this.bottom = true;
		this.color = color;

	}


	public ShadowFrame(int px, boolean right, boolean left, boolean top, boolean bottom) {
		super();
		this.px = px;
		this.right = right;
		this.left = left;
		this.top = top;
		this.bottom = bottom;
	}


	public ShadowFrame(int px, Color color, boolean right, boolean left, boolean top, boolean bottom) {
		super();
		this.px = px;
		this.right = right;
		this.left = left;
		this.top = top;
		this.bottom = bottom;
		this.color = color;
	}


	@Override
	public void initEffectProperties() {
		int width = getEffectPanel().getWidth();
		int height = getEffectPanel().getHeight();

		r1 = new Rectangle(0, 0, px, height);
		r2 = new Rectangle(width - px, 0, px, height);
		r3 = new Rectangle(0, 0, width, px);
		r4 = new Rectangle(0, height - px, width, px);

		p1 = new GradientPaint(new Point(0, 0), color, new Point(px, 0), new Color(0.0f, 0.0f, 0.0f, 0.0f));
		p2 = new GradientPaint(new Point(width, 0), color, new Point(width - px, 0), new Color(0.0f, 0.0f, 0.0f, 0.0f));
		p3 = new GradientPaint(new Point(0, 0), color, new Point(0, px), new Color(0.0f, 0.0f, 0.0f, 0.0f));
		p4 = new GradientPaint(new Point(0, height), color, new Point(0, height - px), new Color(0.0f, 0.0f, 0.0f, 0.0f));
	}


	@Override
	public void doPaintBefore(Graphics2D g) {
	}


	@Override
	public void doPaintAfter(Graphics2D g) {
		defaultPaint = g.getPaint();
		if (this.left) {
			g.setPaint(p1);
			g.fill(r1);
		}
		if (this.right) {
			g.setPaint(p2);
			g.fill(r2);
		}
		if (this.top) {
			g.setPaint(p3);
			g.fill(r3);
		}
		if (this.bottom) {
			g.setPaint(p4);
			g.fill(r4);
		}
		g.setPaint(defaultPaint);
	}
}
